Token Parsing Error .. encountered \' .. in Beanshell?
NickName:Arvind Ask DateTime:2012-06-28T07:10:07

Token Parsing Error .. encountered \' .. in Beanshell?

I am trying to run the following Beanshell code--

assignee.toString()!=''

Here 'assignee' is a variable in Beanshell context.

But I am getting the following error--

Caused by: Sourced file: inline evaluation of: ``assignee.toString()!='';'' Token Parsing Error: Lexical error at line 1, column 23.  Encountered: "\'" (39), after : "\'": <at unknown location>

at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at org.webharvest.runtime.scripting.BeanShellScriptEngine.eval(BeanShellScriptEngine.java:104)

What am I doing wrong here? I want to check if the variable 'assignee' has a null value or not... What is the correct way of accomplishing this?

Copyright Notice:Content Author:「Arvind」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11236032/token-parsing-error-encountered-in-beanshell

Answers
user166390 2012-06-27T23:17:08

The issue is that 'c' is a character literal, but '' (a character literal for \"no character\"?) is invalid Java syntax. (Even if it did parse there would be a type error with String == char.)\n\nPerhaps \"\" (an empty String) literal was meant instead?\n\nImportant Note: even if this doesn't have a Syntax Error one should generally not compare Strings with == (or !=) as the results can be unexpected.. There are plenty of questions on SO as to why and how to properly compare String objects in Java: e.g. see String.equals(..) and String.isEmpty().\n\nHappy coding!",


More about “Token Parsing Error .. encountered \' .. in Beanshell?” related questions